package com.cloudcc.mobile.adapter;


import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.TextView;

import com.cloudcc.cloudframe.adapter.CommonAdapter;
import com.cloudcc.cloudframe.adapter.ViewHolder;
import com.cloudcc.mobile.R;
import com.cloudcc.mobile.entity.approval.TaskApprovalHistoryModel;
import com.cloudcc.mobile.entity.approval.TaskApprovalHistoryModel.Instancehis;
import com.cloudcc.mobile.util.ViewUtils;

public class TmVerticalTimelineAdapter extends CommonAdapter<TaskApprovalHistoryModel>{
	public TmVerticalTimelineAdapter(Context mContext) {
		super(mContext);
		
	}
	@Override
	public void convert(ViewHolder holder, TaskApprovalHistoryModel t) {
		ViewText viewtext = new ViewText();
		viewtext.textview1 = holder.getView(R.id.tv_operation_man);
		viewtext.textview2 = holder.getView(R.id.tv_operation_state);
		viewtext.textview3 = holder.getView(R.id.tv_operation_time);
		int i = holder.getPostion();
		if(i==0){
			holder.getView(R.id.vt_view1).setVisibility(View.INVISIBLE);
		}else if(i == getCount()-1){
			holder.getView(R.id.vt_view2).setVisibility(View.INVISIBLE);
		}
		Instancehis instancehis = t.getInstancehis().get(0);
		String stepStatus = instancehis.stepStatus;
		String comments = instancehis.comments;
		if(comments==null||comments.equals("null")){
			comments = "";
		}
		if(stepStatus.equals("Started") || stepStatus.equals("已提交")){
			ViewUtils.setText(viewtext.textview1, "发起人："+instancehis.actualName);
			ViewUtils.setText(viewtext.textview2, "发起内容："+comments);
			ViewUtils.setText(viewtext.textview3, "发起时间："+instancehis.lastModifyDate);
		}else if(stepStatus.equals("Pending") || stepStatus.equals("审批中")){
			ViewUtils.setText(viewtext.textview1, "待审批人："+instancehis.actualName);
			viewtext.textview1.setTextColor(Color.BLUE);
			ViewUtils.setText(viewtext.textview2, "审批状态："+stepStatus);
			viewtext.textview2.setTextColor(Color.BLUE);
			holder.setSrc(R.id.vt_imageview, R.drawable.ball_red);
			holder.getView(R.id.tv_operation_time).setVisibility(View.GONE);
		}else if(stepStatus.equals("Recalled") || stepStatus.equals("调回")){
			ViewUtils.setText(viewtext.textview1, "调回人："+instancehis.actualName);
			ViewUtils.setText(viewtext.textview2, "调回状态："+stepStatus);
			ViewUtils.setText(viewtext.textview3, "调回时间："+instancehis.lastModifyDate);
		}else{
			ViewUtils.setText(viewtext.textview1, "审批人："+instancehis.actualName);
			ViewUtils.setText(viewtext.textview2, "审批状态："+stepStatus);
			ViewUtils.setText(viewtext.textview3, "审批时间："+instancehis.lastModifyDate);
		}
	}

	@Override
	public int getLayoutId() {
		// TODO Auto-generated method stub
		return R.layout.vertical_timeline;
	}
	
	class ViewText{
		private TextView textview1;
		private TextView textview2;
		private TextView textview3;
	}
}
